<?php
require_once('config.php'); 

$like = false;
$fan_id = "default";

function parsePageSignedRequest() {
	if (isset($_REQUEST['signed_request'])) {
		$encoded_sig = null;
		$payload = null;
		list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
		$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
		$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
		return $data;
	}
	return false;
}

if ($signed_request = parsePageSignedRequest()) {
	if ($signed_request->page->liked) {
		$like = true;
	} else {
		$like = false;
	}
	if($signed_request->page->id)
	{
		$fan_id = $signed_request->page->id;
	}
}
if ( isset($_SERVER['HTTP_REFERER']) && !preg_match("/http:\/\/static\.ak\.facebook\.com\/platform\/page_proxy\.php/", $_SERVER['HTTP_REFERER']) )
{
	if( isset( $_GET['like'] )  && ( $_GET['like'] == true || $_GET['like'] == 1 ) )
	{
		$like = true;
	}
}